<style lang="less">
    @import './index.less';
</style>

<template>
    <div>
        <Row :gutter="10">
            <i-col span="24">
            <div class="page-content">
                <Row style="height: 24px;line-height: 24px;margin-bottom: 10px;">
                    <i-col>
                    <span style="font-size: 14px">当前客户端名称:</span><span
                        style="font-size: 14px;display: inline-block;margin-right:20px;">{{app}}</span>
                    <Button type="primary" size="small" @click="initAppPage">
                        刷新客户端页面
                    </Button>
                    </i-col>
                </Row>
                <div>
                    <Row :gutter="10">
                        <i-col v-for="p in pages" :key="p.name" span="6">

                        <Card style="margin-bottom: 10px">
                            <p slot="title">
                                {{p.name}}
                            </p>
                            <div>
                                <h3 style="color:#ed3f14">描述 : {{p.title}}</h3>
                                <p>功能权限入口 : </p>
                                <p v-for="ac in p.controls" :key="p.name+ac.key">
                                    {{ac.label}}
                                </p>
                            </div>
                        </Card>
                        </i-col>
                    </Row>
                </div>
            </div>
            </i-col>
        </Row>
    </div>
</template>

<script>
  import {appRouter, appName} from '@/router/router';
  import _ from 'lodash';
  export default {
    data () {
      return {
        self: this,
        pages: [],
        app: appName
      };
    },
    methods: {
      initAppPage () {
        this.$http.post('/sys/pages', this.pages)
          .then((res) => {
            this.$Message.info('刷新成功,请检查响应权限');
          })
          .catch((e) => {
            this.$Message.error(e.message);
          });
      }
    },
    components: {},
    computed: {},
    watch: {},
    mounted () {
      let self = this;
      appRouter.forEach(app => {
        app.children.forEach(r => {
          if (r.needAccess) {
            r.app = appName;
            r.component().then(c => {
              r.controls = [];
              _.forEach(c.default.components, (v, k) => {
                if (v.accessLabel) {
                  r.controls.push({key: v.accessKey, label: v.accessLabel + '功能'});
                }
              });
              r.controls.push({key: r.name, label: '页面显示'});
              self.pages.push(r);
            });
          }
        });
      });
    }
  };
</script>
